<include file="public/layout"/>


<?php

//获取系统的第一个会员
$usermod=M("Users");
$levels = M('UserLevel')->getField('rank,level_name');
$rs_hy=$usermod->where(array('user_id'=>1))->field(true)->find();
$hyid=$rs_hy["username"];
if (!empty($_REQUEST['userid'])){
    $hyid=$_REQUEST['userid'];
    //查询会员是否存在
    $rs_chk=$usermod->where(array('username'=>$hyid))->field(true)->find();
    if (empty($rs_chk["user_id"])){
        die("查询会员不存在");
    }
}


?>
<table width="100%" border="0">
    <form name="searchform" method="post" action="{:U('Users/glnet')}">
        <tr style=" display:">
            <td height="30" align="center"><span id="Label1">会员编号：</span>

                <input name="userid" type="text" class="input-text" size="25" value="{$_REQUEST['userid']}"/>
              
                <input type="submit" name="btnSearch" value="搜索" id="btnSearch" class="btn">
                <input type="button" onclick="exportReportgl('{$hyid}')" name="export" value="导出" class="btn">
            </td>

          
        </tr>
    </form>
</table>
<?php
if ($hyid!=""){ 
	$rs11=$usermod->where(array('username'=>$hyid))->field(true)->find();

if (empty($rs11["user_id"])){
die("没有找到相应的会员") ;
}
echo "<br>
<div align=\"center\">";
    if (!empty($rs11["gl_id"])){
   
    ?>
    <input type="button" name="btnSearch" value="上一层" id="btnSearch" class="btn"
           onClick="window.location.href='{:U('Users/glnet',array('userid'=>$rs11['gl_username']))}'">
    <input type="button" name="btnSearch" value="置顶" id="btnSearch" class="btn"
           onClick="window.location.href='{:U('Users/glnet',array('userid'=>$rs_hy['username']))}'">
    <?php
	}
	?>
</div>
<br>
<table align="center" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td valign="top">
            <table width="100" border="1" cellpadding="0" cellspacing="1" bgcolor="#517DBF" align="center">
                <tr>
                    <td align="center" bgcolor="#E7F2FB">
                        <table width="100%" border="0" cellspacing="1" cellpadding="0" style="margin:0px auto 0 auto;">
                            <tr>
                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                  href="{:U('Users/glnet',array('userid'=>$rs11['username']))}"><font><strong>{$levels[$rs11["level"]]}{$rs11['gl_pos']}</strong></font></a>
                                </td>
                            </tr>
                            <tr>
                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                  href="{:U('Users/glnet',array('userid'=>$rs11['username']))}"><font><strong>{$rs11["username"]}<br >{$rs11["nickname"]}<if condition="$rs11['jihuo'] eq 0"><br /><span style="color:blue;">未激活</span></if></strong></font></a>
                                </td>
                            </tr>
                            <tr>
                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                  href="{:U('Users/glnet',array('userid'=>$rs11['username']))}"><font><strong>{$rs11['jw_time']|date='Y-m-d H:i:s',###}</strong></font></a>
                                </td>
                            </tr>

                            <tr>
                                <td align="center" bgcolor="#66c2cd">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#E7F2FB">
                                        <tbody bgcolor="#c9e8ec">
                                        <tr>
                                            <td></td>
                                            <td>左</td>
                                            <td>右</td>
                                        </tr>
                                        <tr>
                                            <td>总</td>
                                            <td>{$rs11['gl_left_totalnum']}</td>
                                            <td>{$rs11['gl_right_totalnum']}</td>
                                        </tr>
                                        <tr>
                                            <td>月</td>
                                            <td>{$rs11['gl_left_monthnum']}</td>
                                            <td>{$rs11['gl_right_monthnum']}</td>
                                        </tr>
                                        <tr>
                                            <td>日</td>
                                            <td>{$rs11['gl_left_daynum']}</td>
                                            <td>{$rs11["gl_right_daynum"]}</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <?php
			$rs_c=$usermod->where(array('gl_id'=>$rs11["user_id"]))->count(1);
            if ($rs_c>0){
            ?>
            <table border="0" align="center" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="/public/images/line.gif"
                                            border="0"/></td>
                </tr>
            </table>
            <?php
			}
			function tuopu_tree($tj_username,$dtp,$dtp1,$levels){
				$usermod=M("Users");
				if ($dtp1<=$dtp){
					$rss=$usermod->
            where(array('gl_id'=>$tj_username))->field('user_id,username,jihuo,gl_pos,level,jw_time,gl_left_totalnum,gl_right_totalnum,gl_left_monthnum,gl_right_monthnum,gl_left_daynum,gl_right_daynum,nickname,is_daoru,htstatus')->order('gl_pos desc')->select();
            $c_num=count($rss);
            if($c_num==1){
                if($rss[0]['gl_pos']=='左'){
                    $rss[1]['user_id']=0;
                    $rss[1]['pos']=2;
                }else{
                    $new = $rss[0];

                    unset($rss[0]);
                    $rss[0]['user_id']=0;
                    $rss[0]['pos']=1;
                    $rss[1] = $new;
                }

            }elseif($c_num==0){

                $rss=[
                    ['user_id'=>0,'pos'=>1],
                    ['user_id'=>0,'pos'=>2],
                ];
            }
            $c_num=2;
            $i=1;

            ?>
            <table align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <?php
					foreach($rss as $key=>$rs) {

                    ?>
                    <td valign="top">
                        <?php
					if ($c_num>1){
                        if (($i==1) && ($c_num>$i)){
                        ?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td align="center">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td width="50%" height="1"></td>
                                            <td width="50%" height="1" bgcolor="#003399"></td>
                                        </tr>
                                    </table>
                                    <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="/public/images/line.gif"
                                         border="0"/></td>
                            </tr>
                        </table>
                        <?php
						}else if(($i>1) && ($c_num==$i)){
                        ?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td align="center">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td width="50%" height="1" bgcolor="#003399"></td>
                                            <td width="50%" height="1"></td>
                                        </tr>
                                    </table>
                                    <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="/public/images/line.gif"
                                         border="0"/></td>
                            </tr>
                        </table>
                        <?php
						}else{
						?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td align="center">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td width="50%" height="1" bgcolor="#003399"></td>
                                            <td width="50%" height="1" bgcolor="#003399"></td>
                                        </tr>
                                    </table>
                                    <img src="/public/images/line.gif" alt="" width="27" border="0"
                                         style="WIDTH: 1px; HEIGHT: 20px"/></td>
                            </tr>
                        </table>
                        <?php
						}
					}
					?>


                        <table width="100" border="1" cellpadding="0" cellspacing="1" bgcolor="#517DBF" align="center">
                            <tr>
                                <td align="center" bgcolor="#E7F2FB">
                                    <if condition="$rs['user_id']">
                                        <table width="100%" border="0" cellspacing="1" cellpadding="0"
                                               style="margin:0px auto 0 auto;">
                                            <tr>
                                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                                  href="{:U('Users/glnet',array('userid'=>$rs['username']))}"><font
                                                        color=""><strong>{$levels[$rs["level"]]}{$rs['gl_pos']}</strong>

                                                    </font></a></td>
                                            </tr>
                                            <tr>
                                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                                  href="{:U('Users/glnet',array('userid'=>$rs['username']))}"><font
                                                        color=""><strong>{$rs["username"]}<br >{$rs["nickname"]}<if condition="$rs['jihuo'] eq 0"><br /><span style="color:blue;">未激活</span></if></strong></font></a></td>
                                            </tr>

                                            <tr>
                                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                                  href="{:U('Users/glnet',array('userid'=>$rs['username']))}"><font
                                                        color=""><strong>{$rs['jw_time']|date='Y-m-d H:i:s',###}</strong></font></a></td>
                                            </tr>

                                            <tr>
                                                <td align="center" bgcolor="#66c2cd">
                                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#E7F2FB">
                                                        <tbody bgcolor="#c9e8ec">

                                                        <tr>
                                                            <td></td>
                                                            <td>左</td>
                                                            <td>右</td>
                                                        </tr>
                                                        <tr>
                                                            <td>总</td>
                                                            <td>{$rs['gl_left_totalnum']}</td>
                                                            <td>{$rs['gl_right_totalnum']}</td>
                                                        </tr>
                                                        <tr>
                                                            <td>月</td>
                                                            <td>{$rs['gl_left_monthnum']}</td>
                                                            <td>{$rs['gl_right_monthnum']}</td>
                                                        </tr>
                                                        <tr>
                                                            <td>新</td>
                                                            <td>{$rs['gl_left_daynum']}</td>
                                                            <td>{$rs['gl_right_daynum']}</td>
                                                        </tr>


                                                        </tbody>
                                                    </table>
                                                </td>
                                            </tr>

                                        </table>
                                        <else />
                                        <table width="100%" border="0" cellspacing="1" cellpadding="0"
                                               style="margin:0px auto 0 auto;">
                                            <tr>
                                                <td height="20" align="center"><a style="WIDTH: 100px;"
                                                                                  href="#"><font
                                                        color=""><strong>暂无</strong></font></a></td>
                                            </tr>



                                        </table>
                                    </if>
                                </td>
                            </tr>
                        </table>


                        <div style="display:block" id="table_{$rs['user_id']}">
                            <?php
                            if($rs['user_id'])
					$rs1=$usermod->where(array('gl_id'=>$rs["user_id"]))->count(1);
                            if ($dtp1<$dtp){
                            if ($rs1>0){
                            ?>
                            <table align="center" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt=""
                                                            src="/public/images/line.gif" border="0"/></td>
                                </tr>
                            </table>
                            <?php
						}
						if ($rs1==1){
						?>
                            <table align="center" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td align="center"><img src="/public/images/line.gif" alt="" width="8" border="0"
                                                            style="WIDTH: 1px; HEIGHT: 20px"/></td>
                                </tr>
                            </table>
                            <?php
						}
					}
					if($rs['user_id']){
					tuopu_tree($rs["user_id"],$dtp,$dtp1+1,$levels);
					}
					?>
                        </div>
                    </td>
                    <?php
					$i++;
					}
					?>
                </tr>
            </table>
            <?php
				}
			}
			
			tuopu_tree($rs11["user_id"],3,1,$levels);
			?>
        </td>
    </tr>
</table>

<?php
}
?>
<script>

    function exportReportgl(username){
        //        var selected_ids = '';
        //        $('.trSelected' , '#flexigrid').each(function(i){
        //            selected_ids += $(this).data('order-id')+',';
        //        });
        //        if(selected_ids != ''){
        //            $('input[name="order_ids"]').val(selected_ids.substring(0,selected_ids.length-1));
        //        }
        var url = '/admin/Users/export_glnet/username/'+username
        window.location.href=url
//        $('#search-form2').attr('action','{:U("Users/export_order",$search)}');
//        $('#search-form2').submit();
//        $('#search-form2').attr('action','{:U("Users/index")}');
    }
</script>
</body>
</html>

